﻿using System;
using System.Web;
using System.Web.Caching;
using MvcWebScraper.Core;

namespace MvcWebScraper.Web
{
	public class WebCache<T> : ICache<T>
		where T : class
	{
		private Func<HttpContextBase> _contextAccesor;
		public WebCache(Func<HttpContextBase> contextAccesor)
		{
			_contextAccesor = contextAccesor;
		}
		public T this[string key]
		{
			get
			{
				return _contextAccesor().Cache[key] as T;
			}

			set
			{
				_contextAccesor().Cache.Insert(key, value, null, DateTime.Now.AddHours(1),
				                                                         Cache.NoSlidingExpiration);
			}
		}
	}
}
